<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    function instanceTest(left, right) {
      if (typeof left !== 'object' || left === null) return false
      let proto = Object.getPrototypeOf(left)
      let i = 0
      while (true) {
        console.log('proto==', proto)
        if (proto === null) return false
        if (proto === right.prototype) return true
        proto = Object.getPrototypeOf(proto)
      }
    }

    function Parent(name, age) {
      this.name = name
      this.age = age
    }
    Parent.prototype.getName = function () {
      console.log(this.name)
    }
    let p1 = new Parent('zhen', 28)
    // console.log('p1', p1 instanceof Parent)

    function Child() {}
    // console.log(p1 instanceof Child)
    // instanceTest(p1, Child)

    function Child2() {
      Parent.call(this)
      this.type = 'child2-type'
    }
    Child2.prototype = Object.create(Parent.prototype)
    //  等同于 Child2.prototype.__proto__ = Parent.prototype;
    Child2.prototype.constructor = Child2
    let child2 = new Child2()
    // console.log('Child2', child2 instanceof Child2)
    // console.log('Parent', child2 instanceof Parent)
    instanceTest(child2, Parent)
    let tt = Object.getPrototypeOf(child2)
    console.log(222, tt)
    console.log(333, Object.getPrototypeOf(tt))
    console.log(Parent.prototype)
    let newObj = {}
    // const newObj = Object.create({
    //   name: 'zhen',
    // })
    // newObj.__proto__ = { name: 'zhen' }
    // console.log(newObj)
  </script>
</html>
